package leecode

import "math"

func MaxSubArray(nums []int) int {
	if len(nums) == 1 {
		return nums[0]
	}
	var maxNum int
	maxNum = math.MinInt64
	var sum int
	for i := 0; i < len(nums); i++ {
		sum = sum + nums[i]
		if sum > maxNum {
			maxNum = sum
		}
		if sum < 0 {
			//遇见连续的复数,从新计数
			sum = 0
		}
	}
	return maxNum
}
